package com.peng.crm.workbench.service.impl;

import com.peng.crm.settings.dao.UserDao;
import com.peng.crm.workbench.dao.ClueRemarkDao;
import com.peng.crm.workbench.entity.ActivityRemark;
import com.peng.crm.workbench.entity.ClueRemark;
import com.peng.crm.workbench.service.ClueRemarkService;
import com.peng.crm.workbench.util.IDSelNameUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索备注(ClueRemark)表服务实现类
 *
 * @author makejava
 * @since 2022-07-02 19:11:34
 */
@Service
public class ClueRemarkServiceImpl implements ClueRemarkService {

    @Autowired
    private ClueRemarkDao clueRemarkDao;

    @Autowired
    private UserDao userDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ClueRemark selectById(String id) {
        return this.clueRemarkDao.selectById(id);
    }

    /**
     * 根据ID查询所有备注信息
     * @param clueId  线索ID
     * @return
     */
    @Override
    public List<ClueRemark> selectList(String clueId) {
        List<ClueRemark> clueRemarks = clueRemarkDao.selectList(clueId);
        IDSelNameUtil idSelNameUtil = new IDSelNameUtil();
        idSelNameUtil.setUserDao(userDao);
        for (ClueRemark clueRemark : clueRemarks) {
            clueRemark.setCreateBy(idSelNameUtil.getUserName(clueRemark.getCreateBy()));
        }
        return clueRemarks;
    }

    /**
     * 添加一条备注信息
     * @param clueRemark    实例对象
     * @return              true/false
     */
    @Override
    public boolean insert(ClueRemark clueRemark) {
        return clueRemarkDao.insert(clueRemark)>0;
    }

    /**
     * 修改一条备注信息
     * @param clueRemark    实例对象
     * @return              true/false
     */
    @Override
    public boolean update(ClueRemark clueRemark) {
        return clueRemarkDao.update(clueRemark)>0;
    }

    /**
     * 删除一条备注信息
     * @param id    标识
     * @return              true/false
     */
    @Override
    public boolean deleteById(String id) {
        return clueRemarkDao.deleteById(id)>0;
    }
}
